package com.junbao.message.infrastructure.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lmax.disruptor.EventFactory;

/**
 * 数据工厂
 * @author yilin
 * @param <T>
 *
 */
@SuppressWarnings("all")
public class DataEventFactory implements EventFactory<RequestDto>{

	private static final Logger LOGGER = LoggerFactory.getLogger(DataEventFactory.class);
	
	private Class<RequestDto> eventTypeClass;
	
	public DataEventFactory(Class<RequestDto> eventTypeClass){
		this.eventTypeClass = eventTypeClass;
	}
	
	@Override
	public RequestDto newInstance() {
		RequestDto eventInstance = null;
		try {
			eventInstance = eventTypeClass.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			LOGGER.error("实例化消息对象失败，消息对象类型 => "+ eventTypeClass, e );
		}
		return eventInstance;
	}

	public Class<RequestDto> getEventTypeClass() {
		return eventTypeClass;
	}

	public void setEventTypeClass(Class<RequestDto> eventTypeClass) {
		this.eventTypeClass = eventTypeClass;
	}
}
